<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.camunda.bpm.wildfly</groupId>
    <artifactId>camunda-wildfly26</artifactId>
    <version>7.20.0-SNAPSHOT</version>
  </parent>

  <artifactId>camunda-wildfly26-modules</artifactId>
  <packaging>jar</packaging>
  <name>Camunda Platform - Wildfly 26 Modules</name>

  <properties>
    <org.jboss.shrinkwrap.resolver.version>1.0.0-beta-5</org.jboss.shrinkwrap.resolver.version>
    <version.json-path>2.8.0</version.json-path>
    <version.json-smart>2.4.10</version.json-smart>
    <version.accessors-smart>2.4.9</version.accessors-smart>
    <!-- generate a bom of compile time dependencies for the license book.
    Note: Every compile time dependency will end up in the license book. Please
    declare only dependencies that are actually needed -->
    <skip-third-party-bom>false</skip-third-party-bom>
    <!-- json-smart and accessors-smart are runtime dependencies of json-path -->
    <third-party-bom-scopes>compile|runtime</third-party-bom-scopes>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.camunda.bpm.wildfly</groupId>
      <artifactId>camunda-wildfly26-subsystem</artifactId>
      <version>${project.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-email</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-beans</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-lang</groupId>
          <artifactId>commons-lang</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.camunda.bpm.identity</groupId>
      <artifactId>camunda-identity-ldap</artifactId>
    </dependency>

    <dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-engine-plugin-spin</artifactId>
    </dependency>

    <dependency>
      <groupId>org.camunda.spin</groupId>
      <artifactId>camunda-spin-dataformat-json-jackson</artifactId>
    </dependency>

    <dependency>
      <groupId>org.camunda.spin</groupId>
      <artifactId>camunda-spin-dataformat-xml-dom</artifactId>
    </dependency>

    <dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-engine-plugin-connect</artifactId>
    </dependency>

    <dependency>
      <groupId>org.camunda.connect</groupId>
      <artifactId>camunda-connect-http-client</artifactId>
    </dependency>

    <dependency>
      <groupId>org.camunda.connect</groupId>
      <artifactId>camunda-connect-soap-http-client</artifactId>
    </dependency>

    <!-- script engine dependencies -->
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy</artifactId>
    </dependency>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-jsr223</artifactId>
    </dependency>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-json</artifactId>
    </dependency>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-xml</artifactId>
    </dependency>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-templates</artifactId>
    </dependency>

    <dependency>
      <groupId>org.graalvm.js</groupId>
      <artifactId>js</artifactId>
    </dependency>
    <dependency>
      <groupId>org.graalvm.js</groupId>
      <artifactId>js-scriptengine</artifactId>
    </dependency>

    <!-- template engine dependencies -->
    <dependency>
      <groupId>org.freemarker</groupId>
      <artifactId>freemarker</artifactId>
    </dependency>

    <dependency>
      <groupId>org.camunda.template-engines</groupId>
      <artifactId>camunda-template-engines-freemarker</artifactId>
    </dependency>

    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
    </dependency>

  </dependencies>

  <build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-dependencies</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <dependencyfilesets scopes="compile,runtime" />

                <mkdir dir="target/modules" />

                <!-- copy all files -->
                <copy todir="target/modules" flatten="false">
                  <fileset refid="maven.project.dependencies" />
                  <regexpmapper from="^(.*)/([^/]+)/([^/]*)$$" to="\1/main/\3" handledirsep="yes" />
                </copy>

                <delete dir="target/modules/org/camunda/bpm" />

                <!-- copy all files again, but this only matches fox files and this treatment makes is maven 2/3 compatible => timestamped snapshot -->
                <copy todir="target/modules" flatten="false">
                  <fileset refid="maven.project.dependencies" />
                  <mapper>
                    <chainedmapper>
                      <regexpmapper from="^(.*)/([^/]+)/([^/]*)$$" to="\1/main/\3" handledirsep="yes" />
                      <regexpmapper from="^(org.camunda.bpm.*)/((camunda-[A-Za-z-]*)[0-9\.]*).*.jar$$" to="\1/\3${project.version}.jar" handledirsep="yes" />
                    </chainedmapper>
                  </mapper>
                </copy>

                <delete dir="target/modules/org/camunda/bpm/wildfly" />
                <copy todir="target/modules" flatten="false">
                  <fileset refid="maven.project.dependencies" />
                  <mapper>
                    <chainedmapper>
                      <regexpmapper from="^(.*)/([^/]+)/([^/]*)$$" to="\1/main/\3" handledirsep="yes" />
                      <regexpmapper from="^(org.camunda.bpm.wildfly.*)/((camunda-wildfly26-[A-Za-z-]*)[0-9\.]*).*.jar$$" to="\1/\3${project.version}.jar" handledirsep="yes" />
                    </chainedmapper>
                  </mapper>
                </copy>

                <copy todir="target/modules/org/camunda/bpm/wildfly/camunda-wildfly-subsystem" flatten="false">
                  <fileset dir="target/modules/org/camunda/bpm/wildfly/camunda-wildfly26-subsystem" includes="**/*.jar" />
                </copy>
                <delete dir="target/modules/org/camunda/bpm/wildfly/camunda-wildfly26-subsystem" />

                <delete dir="target/modules/org/camunda/spin" />
                <copy todir="target/modules" flatten="false">
                  <fileset refid="maven.project.dependencies" />
                  <mapper>
                    <chainedmapper>
                      <regexpmapper from="^(.*)/([^/]+)/([^/]*)$$" to="\1/main/\3" handledirsep="yes" />
                      <regexpmapper from="^(org.camunda.spin.*)/((camunda-[A-Za-z-]*)[0-9\.]*).*.jar$$" to="\1/\3${version.camunda.spin}.jar" handledirsep="yes" />
                    </chainedmapper>
                  </mapper>
                </copy>

                <delete dir="target/modules/org/camunda/connect" />
                <copy todir="target/modules" flatten="false">
                  <fileset refid="maven.project.dependencies" />
                  <mapper>
                    <chainedmapper>
                      <regexpmapper from="^(.*)/([^/]+)/([^/]*)$$" to="\1/main/\3" handledirsep="yes" />
                      <regexpmapper from="^(org.camunda.connect.*)/((camunda-[A-Za-z-]*)[0-9\.]*).*.jar$$" to="\1/\3${version.camunda.connect}.jar" handledirsep="yes" />
                    </chainedmapper>
                  </mapper>
                </copy>

                <!-- do not include connectors-all dependency, because
                  we are using the individual connect modules on Wildfly -->
                <delete dir="target/modules/org/camunda/connect/camunda-connect-connectors-all" />

                <delete dir="target/modules/org/camunda/commons" />
                <copy todir="target/modules" flatten="false">
                  <fileset refid="maven.project.dependencies" />
                  <mapper>
                    <chainedmapper>
                      <regexpmapper from="^(.*)/([^/]+)/([^/]*)$$" to="\1/main/\3" handledirsep="yes" />
                      <mapper>
                        <regexpmapper from="^(org.camunda.commons.*)\/((camunda-commons-(utils|logging)-[A-Za-z-]*)[0-9\.]*).*.jar$$" to="\1/\3${version.camunda.commons}.jar" handledirsep="yes" />
                        <regexpmapper from="^(org.camunda.commons.*)\/((camunda-commons-typed-values-)[0-9\.]*).*.jar$$" to="\1/\3${project.version}.jar" handledirsep="yes" />
                      </mapper>
                    </chainedmapper>
                  </mapper>
                </copy>

                <delete dir="target/modules/org/camunda/template-engines" />
                <copy todir="target/modules" flatten="false">
                  <fileset refid="maven.project.dependencies" />
                  <mapper>
                    <chainedmapper>
                      <regexpmapper from="^(.*)/([^/]+)/([^/]*)$$" to="\1/main/\3" handledirsep="yes" />
                      <regexpmapper from="^(org.camunda.template-engines.*)/((camunda-[A-Za-z-]*)[0-9\.]*).*.jar$$" to="\1/\3${version.camunda.template-engines}.jar" handledirsep="yes" />
                    </chainedmapper>
                  </mapper>
                </copy>

                <delete dir="target/modules/org/camunda/feel" />
                <copy todir="target/modules" flatten="false">
                  <fileset refid="maven.project.dependencies" />
                  <mapper>
                    <chainedmapper>
                      <regexpmapper from="^(.*)/([^/]+)/([^/]*)$$" to="\1/main/\3" handledirsep="yes" />
                      <regexpmapper from="^(org.camunda.feel.feel-engine.*)/(([A-Za-z-]*)[0-9\.]*).*.jar$$" to="\1/\3${version.feel-scala}-scala-shaded.jar" handledirsep="yes" />
                    </chainedmapper>
                  </mapper>
                </copy>

                <!-- copy jackson dependencies to slot -->
                <delete dir="target/modules/com/fasterxml/jackson" />
                <copy todir="target/modules" flatten="false">
                  <fileset refid="maven.project.dependencies" />
                  <mapper>
                    <chainedmapper>
                      <regexpmapper from="^(.*)/([^/]+)/([^/]*)$$" to="\1/${version.jackson}/\3" handledirsep="yes" />
                      <regexpmapper from="^(com.fasterxml.jackson.*)\/((jackson.*-)[0-9\.]*).*.jar$$" to="\1/\3${version.jackson}.jar" handledirsep="yes" />
                    </chainedmapper>
                  </mapper>
                </copy>

                <!-- copy groovy dependencies to single dir -->
                <delete dir="target/modules/org/codehaus/groovy" />
                <copy todir="target/modules" flatten="false">
                  <fileset refid="maven.project.dependencies" />
                  <mapper>
                    <chainedmapper>
                      <regexpmapper from="^(.*)/([^/]+)/([^/]+)/([^/]*)$$" to="\1/groovy-all/main/\4" handledirsep="yes" />
                      <regexpmapper from="^(org.codehaus.groovy.*/.*.jar)$$" to="\1" handledirsep="yes" />
                    </chainedmapper>
                  </mapper>
                </copy>

                <copy todir="target/modules" flatten="false">
                  <fileset dir="src/main/modules" />
                </copy>

                <replace dir="target/modules" token="@project.version@" value="${project.version}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.camunda.commons@" value="${version.camunda.commons}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.camunda.spin@" value="${version.camunda.spin}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.camunda.connect@" value="${version.camunda.connect}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.camunda.template-engines@" value="${version.camunda.template-engines}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.freemarker@" value="${version.freemarker}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.groovy@" value="${version.groovy}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.jackson@" value="${version.jackson}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.json-path@" value="${version.json-path}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.json-smart@" value="${version.json-smart}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.accessors-smart@" value="${version.accessors-smart}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.h2@" value="${version.h2}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.mybatis@" value="${version.mybatis}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.feel-scala@" value="${version.feel-scala}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.graal.js@" value="${version.graal.js}">
                  <include name="**/module.xml" />
                </replace>

                <replace dir="target/modules" token="@version.icu.icu4j@" value="${version.icu.icu4j}">
                  <include name="**/module.xml" />
                </replace>

              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>joda-time</groupId>
                  <artifactId>joda-time</artifactId>
                  <outputDirectory>${project.build.directory}/modules/org/joda/time/2.1/</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <classesDirectory>${project.build.directory}/modules/</classesDirectory>
        </configuration>
      </plugin>

      <!-- assemble zip artifact -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
          <execution>
            <id>assemble</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <descriptors>
                <descriptor>assembly.xml</descriptor>
              </descriptors>
              <attach>true</attach>
              <appendAssemblyId>false</appendAssemblyId>
              <outputDirectory>target/</outputDirectory>
              <workDirectory>target/assembly/work</workDirectory>
              <tarLongFileMode>gnu</tarLongFileMode>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
